package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.RecordAdapter;
import flc.ast.bean.RecordBean;
import flc.ast.databinding.ActivityFormatRecordBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.utils.SPUtil;

public class FormatRecordActivity extends BaseAc<ActivityFormatRecordBinding> {

    private List<RecordBean> listShow=new ArrayList<>();
    private RecordAdapter recordAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_format_record;
    }

    @Override
    protected void initView() {
        mDataBinding.ivFormatRecordBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.rvFormatRecordList.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
        recordAdapter=new RecordAdapter();
        mDataBinding.rvFormatRecordList.setAdapter(recordAdapter);
        mDataBinding.ivFormatRecordDelete.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.ivFormatRecordDelete:
                listShow.clear();
                AppSpUtils.saveRecordList(listShow);
                getData();
                break;
        }
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData(){
        listShow.clear();
        List<RecordBean> listSp = AppSpUtils.getRecordList();
        if (listSp != null && listSp.size() > 0) {
            listShow.addAll(listSp);
            recordAdapter.setList(listShow);
            mDataBinding.rvFormatRecordList.setVisibility(View.VISIBLE);
            mDataBinding.llFormatRecordNoData.setVisibility(View.GONE);
            mDataBinding.ivFormatRecordDelete.setVisibility(View.VISIBLE);
        } else {
            mDataBinding.rvFormatRecordList.setVisibility(View.GONE);
            mDataBinding.llFormatRecordNoData.setVisibility(View.VISIBLE);
            mDataBinding.ivFormatRecordDelete.setVisibility(View.GONE);
        }
    }

}